package schoolWork.work04.test4;

//自定义一个异常类，用于处理银行账户类中取款时如果用户输入的金额是负数或者输入的金额超过余额以及存款时输入的金额是负数时的异常处理。
// (1)取款时用户输入的金额是负数，抛出异常 NegativeAmountException;
// (2)取款时用户输入的金额超过账户余额，抛出异常 InsufficientFundsException;
// (3)存款时用户的金额是负数时，抛出异常 NegativeAmountException。

public class Test {
    public static void main(String[] args) {
        BankAccount bankAccount = new BankAccount(50000);

       try{
           bankAccount.deposit(-1000);
       }catch(Exception e){
           System.out.println(e.getMessage());
       }

        try{
            bankAccount.withdraw(-2000);
        }catch(Exception e){
            System.out.println(e.getMessage());
        }

        try{
            bankAccount.withdraw(60000);
        }catch(Exception e){
            System.out.println(e.getMessage());
        }

        System.out.println("剩余余额为:"+bankAccount.getBalance()+"元");

    }
}
